﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class TestCase_TestFormPost : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        this.dotNetFlexGrid1.InitConfig(
            new string[]{
                "title=false",//标题
                "singleselected=false",//是否单选
                "resizable=false",//是否可以调整大小
                "usepager=true",//使用分页器
                "showcheckbox=true",//显示复选框
                "height=200",//高度，可为auto或具体px值
                "width=auto",//宽度，可为auto或具体px值
                "striped=true",//是否显示行交替色
                "selectedonclick=false"//是否点击行自动选中checkbox
            },
            new dotNetFlexGrid.FieldConfig[]{
                new dotNetFlexGrid.FieldConfig("Guid","编号",60,true,dotNetFlexGrid.FieldConfigAlign.Left,false,false,true),
                new dotNetFlexGrid.FieldConfig("String1","字段1",120,true,dotNetFlexGrid.FieldConfigAlign.Right),
                new dotNetFlexGrid.FieldConfig("String2","字段2",60,true,dotNetFlexGrid.FieldConfigAlign.Left),
                new dotNetFlexGrid.FieldConfig("String3","字段3",60,true,dotNetFlexGrid.FieldConfigAlign.Left),
                new dotNetFlexGrid.FieldConfig("String4","字段4",60,true,dotNetFlexGrid.FieldConfigAlign.Left),
                new dotNetFlexGrid.FieldConfig("Int1","字段5",60,true,dotNetFlexGrid.FieldConfigAlign.Left),
                new dotNetFlexGrid.FieldConfig("Int2","字段6",60,true,dotNetFlexGrid.FieldConfigAlign.Left),
                new dotNetFlexGrid.FieldConfig("DateTime","字段7",60,true,dotNetFlexGrid.FieldConfigAlign.Left),
                new dotNetFlexGrid.FieldConfig("Checked","字段8",60,false,dotNetFlexGrid.FieldConfigAlign.Left,true,true,false)
            },
            null,
            null

        );
        this.dotNetFlexGrid1.DataHandler=new dotNetFlexGrid.DataHandlerDelegate(DotNetFlexGrid1DataHandler);
        this.dotNetFlexGrid1.DefaultSearch.Add("默认查询条件","中文的值");
        if (IsPostBack)
        {
            this.ListBox1.Items.Clear();
            foreach (string s in dotNetFlexGrid1.CheckedRows)
                this.ListBox1.Items.Add(s);
        }
    }
    public dotNetFlexGrid.DataHandlerResult DotNetFlexGrid1DataHandler(dotNetFlexGrid.DataHandlerParams p)
    {
        dotNetFlexGrid.DataHandlerResult result = new dotNetFlexGrid.DataHandlerResult();
        result.page = p.page;
        result.total = 100;
        result.table = MemoryTable(p.page * 100, p.rp);

        return result;
    }
    private DataTable MemoryTable(int start, int num)
    {
        DataTable result = new DataTable("js_flexigrid");
        result.Columns.Add("Guid", System.Type.GetType("System.String"));
        result.Columns.Add("String1", System.Type.GetType("System.String"));
        result.Columns.Add("String2", System.Type.GetType("System.String"));
        result.Columns.Add("String3", System.Type.GetType("System.String"));
        result.Columns.Add("String4", System.Type.GetType("System.String"));
        result.Columns.Add("Int1", System.Type.GetType("System.Int32"));
        result.Columns.Add("Int2", System.Type.GetType("System.Int32"));
        result.Columns.Add("DateTime", System.Type.GetType("System.DateTime"));
        result.Columns.Add("Checked", System.Type.GetType("System.Boolean"));

        for (int i = start; i < num + start; i++)
        {
            DataRow dr = result.NewRow();

            dr["Guid"] = Guid.NewGuid().ToString();
            dr["String1"] = "<b>字段1_" + i.ToString()+"</b>";
            dr["String2"] = "字段2_" + i.ToString();
            dr["String3"] = "字段3_" + i.ToString();
            dr["String4"] = "字段4_" + i.ToString();

            dr["Int1"] = 1 * 100000 + i;
            dr["Int2"] = 2 * 100000 + i;
            dr["DateTime"] = DateTime.Now;
            if (i == start)
                dr["Checked"] = true;
            else
                dr["Checked"] = !true;


            result.Rows.Add(dr);
        }
        return result;
    }
}
